<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>高德地图地址及经纬度查询样例</title>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=2e098085775787cba4cc3985b4e0da6e&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.Geocoder"></script>
<script type="text/javascript" src="http://api.map.baidu.com/library/SearchControl/1.4/src/SearchControl_min.js"></script>
<link rel="stylesheet" href="http://api.map.baidu.com/library/SearchControl/1.4/src/SearchControl_min.css" />
<style type="text/css">  
  html{height:100%;}  
  body{height:100%; margin-left: 50px;}  
  #mymap{width:800px; height:450px; margin-top: 20px;}
  #searchBox, #rsltArea {margin-top: 20px;}
</style> 
</head>
<body>
  <div id="searchBox">
    <input type="text" id="txtSearch" style="width:200px;"></input>
    <input type="button" onclick="searchAddrAndLngLat()" value="查询"></input>
  </div>

  <div id="mymap"></div>
  
  <div id="rsltArea">
    <span style="margin-right: 10px;">地址</span><input type="text" id="txtAddr"></input>
    <span style="margin-right: 10px;">Lat</span><input type="text" id="txtLat"></input>
    <span style="margin-right: 10px;">Lng</span><input type="text" id="txtLng"></input>
  </div>

</body>
<script type="text/javascript">
  // 定义并初始化地图
  var map = new AMap.Map("mymap", {
    showIndoorMap: false, // 是否在有矢量底图的时候自动展示室内地图，PC默认true,移动端默认false
    resizeEnable: true, //是否监控地图容器尺寸变化，默认值为false
    dragEnable: true, // 地图是否可通过鼠标拖拽平移，默认为true
    keyboardEnable: false, //地图是否可通过键盘控制，默认为true
    doubleClickZoom: false, // 地图是否可通过双击鼠标放大地图，默认为true
    zoomEnable: true, //地图是否可缩放，默认值为true
    rotateEnable: false, // 地图是否可旋转，3D视图默认为true，2D视图默认false
  });
  map.setCity('南京');
  map.setZoom(15);

  // 用于搜索地址及经纬度
  // 地址输入自动提示控件定义
  var ac = new AMap.Autocomplete({
      "input" : "txtSearch"
  });
  // 下拉框选择地址后自动获得地址和经纬度
  AMap.event.addListener(ac, "select", function(e){
    document.getElementById("txtSearch").value = e.poi.name;
    searchAddrAndLngLat();
  });
  // 地址检索控件定义
  var local = new AMap.PlaceSearch({
  });
  // 查询地址及经纬度
  function searchAddrAndLngLat() {
    var p = document.getElementById("txtSearch").value;
    local.search(p, function(status, rs) {
      if ('complete' == status) {
        var pois = rs.poiList.pois;
        if (0 < pois.length) {
          debugger;
          geoc.getAddress(pois[0].location, function(status, rs){
            debugger;
            if (status === 'complete' && rs.regeocode) {
              setPlace(rs.regeocode.formattedAddress, pois[0].location);
            }
          });
        }
      }
    });
  }

  // 用于点击地图获得地址和经纬度坐标
  // 逆地址解析器
  var geoc = new AMap.Geocoder({radius: 1000});
  // 鼠标点击获得地址信息
  map.on("click", function(e) {
    geoc.getAddress(e.lnglat, function(status, rs){
      if (status === 'complete' && rs.regeocode) {
        setPlace(rs.regeocode.formattedAddress, e.lnglat);
      }
    });
  });

  var marker;
  // 设置数据
  function setPlace(addr, point) {
    if (marker) {
      map.remove(marker);
      map.setFitView();
    }
    map.setZoomAndCenter(15, [point.getLng(), point.getLat()]);
    marker = new AMap.Marker({
      position: point
    });
    map.add(marker);
    map.setFitView();
    document.getElementById("txtAddr").value=addr;
    document.getElementById("txtLat").value=point.getLat();
    document.getElementById("txtLng").value=point.getLng();
  }

</script>
</html>